

<?php 
	   $cat_result = mysql_query("select * from ".$table_Prefix."term where belong = '$system_part' and interm = 'root' and publish = 1 ");

//print_r2(mysql_fetch_assoc($cat_result));
	   ?>
<div id="cat_list"></div>

  <script>
  layui.use('tree', function(){
  var tree = layui.tree;

  //渲染
    var inst1 = tree.render({
      elem: '#cat_list'  //绑定元素
      ,showCheckbox:true
	  ,id:'cat_list'
	  ,data: [
	  	
		<?php 
					   $i = 0;
					   while ($cat = mysql_fetch_array($cat_result)) { //一级
					   		if($i > 0){echo ',';}
					   ?>
					   {title: '<?php echo $cat['name']?>'
					   ,id: <?php echo $cat['nid']?>
    				   ,field: ''
                       <?
//                        var_dump($relation_term_nid);
						if (compare_term($cat['nid'], $relation_term_nid) == true) {
					   ?>
						,checked:true
						,spread:true
						<?php
						}
						
					   		$i ++;
					   	$cat2_result = mysql_query("select * from ".$table_Prefix."term where belong = '$system_part' and interm = 'term1' and publish = 1 and term1 =  ".$cat['nid']);
							if($cat2_result){
						?>
								,children: [
						<?php	
								$ii = 0;
								while ($cat2 = mysql_fetch_array($cat2_result)) { //二级
									if($ii > 0){echo ',';}
						?>
								{title: '<?php echo $cat2['name']?>'
							     ,id: <?php echo $cat2['nid']?>
							     ,field: ''
								 <?
								if (compare_term($cat2['nid'], $relation_term_nid)) {
							   ?>
								,checked:true
								,spread:true
								<?php
								}
								 $ii++;
								$cat3_result = mysql_query("select * from ".$table_Prefix."term where belong = '$system_part' and interm = 'term2' and publish = 1 and term2 =  ".$cat2['nid']);
                    	    	
									if($cat3_result){
						?>
										,children: [
						<?php
										$iii = 0;
										while ($cat3 = mysql_fetch_array($cat3_result)) { //三级
											
											if($iii > 0){echo ',';}
						?>
                        					{title: '<?php echo $cat3['name']?>'
											,id: <?php echo $cat3['nid']?>
											,field: ''
											<?
											if (compare_term($cat3['nid'], $relation_term_nid)) {
											?>
											,checked:true
											,spread:true
											<?php
											}
											?>
											}
                        <?php		
											
											$iii++;
										}
						?>
										
										]
									}
						<?php
									}
								}
						?>
								]}
						<?php
						    }
					   }
					   ?>
        
		]
    });
	
  });
  
  
  </script>

       